import {
  getBusinessAddSave,
  getBusinessEditDetails,
  getBusinessEditSave,
  getBusinessDelete,
  getBusinessList,
  submitBusiness,
  getHealthList,
  getHealthAddSave,
  getHealthDelete,
  getLicenseList,
  getLicenseAddSave,
  getLicenseDelete,
  getSerialList,
  setSerialUnbind,
  deleteStall,
  getContractList,
  getPayTheFeesList,
  getCheckReportList,
  getPurchaseDetail,
  getBusinessDetailsData,
  getBusinessImg,
  dredgeStatus,
  fetchBankCardImg,
  fetchidCardBackImg,
  fetchidCardFrontImg,
  saveTabsSecond,
  uploadImage,
  realNameClick,
  sendSms,
  changeBankCard,
  msgCodeValid,
  bindcardConfirm,
  bankcardAuth,
  bindCardResetSendSms,
  getAlreadyExist,
  submitAllImg,
  submitStaticCodeImg
} from '@/api/business'
import { getTradingList } from '@/api/operating'
import { Message } from 'element-ui';
export default {
  namespaced: true, // 封闭
  state: {},
  mutations: {},
  getters: {},
  actions: {

    // 先获取已有图片
    async getAlreadyExist(context, payload) {
      const { businessId } = payload
      try {
        const { data } = await getAlreadyExist(businessId)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    async submitAllImg(context, payload) {
      try {
        const { data } = await submitAllImg(payload)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 提交静态码
    async submitStaticCodeImg(context, payload) {
      try {
        const { data } = await submitStaticCodeImg(payload)
        return data
      } catch (err) {
        console.log(err)
      }
    },

    // 点击重发
    async bindCardResetSendSms(context, payload) {
      const { businessId } = payload
      try {
        const { data } = await bindCardResetSendSms(businessId)
        return data
      } catch (err) {
        console.log(err)
      }
    },

    // 银行卡图片 银行卡四元素认证
    async bankcardAuth(context, payload) {
      try {
        const { data } = await bankcardAuth(payload)
        return data
      } catch (err) {
        console.log(err)
      }
    },

    // 【支付】确认绑卡 api
    async bindcardConfirm(context, payload) {
      try {
        const { data } = await bindcardConfirm(payload)
        return data
      } catch (err) {
        console.log(err)
      }
    },

    // 点击验证 验证码有效性验证接口
    async msgCodeValid(context, payload) {
      try {
        const { data } = await msgCodeValid(payload)
        return data
      } catch (err) {
        console.log(err)
      }
    },

    // 银行卡绑定 【支付】变更银行卡，并发送验证码
    async changeBankCard(context, payload) {
      try {
        const { data } = await changeBankCard(payload)
        return data
      } catch (err) {
        console.log(err)
      }
    },

    // 银行卡绑定 验证码发送短信
    async sendSms(context, payload) {
      const { businessId } = payload
      try {
        const { data } = await sendSms(businessId)
        return data
      } catch (err) {
        console.log(err)
      }
    },

    // 实名认证
    async realNameClick(context, payload) {
      try {
        const { data } = await realNameClick(payload)
        return data
      } catch (err) {
        console.log(err)
        Message.error({
          type: 'error',
          message: '认证审核中,不可重复认证'
        })
      }
    },

    // 上传图片认证
    async uploadImage(context, payload) {
      try {
        const { data } = await uploadImage(payload)
        return data
      } catch (err) {
        console.log(err)
        Message.error({
          type: 'error',
          message: '图片认证失败'
        })
      }
    },

    // 开通状态为1 未开通时 编辑保存 第二个tabs的内容
    async saveTabsSecond(context, payload) {
      try {
        const { data } = await saveTabsSecond(payload)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 身份证正面
    async fetchidCardFrontImg(context, payload) {
      const { imgFile, side } = payload
      try {
        const { data } = await fetchidCardFrontImg(imgFile, side)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 身份证反面
    async fetchidCardBackImg(context, payload) {
      const { imgFile, side } = payload
      try {
        const { data } = await fetchidCardBackImg(imgFile, side)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 银行卡识别
    async fetchBankCardImg(context, payload) {
      const { imgFile } = payload
      try {
        const { data } = await fetchBankCardImg(imgFile)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // tabs 为 second 时，获得 开通状态
    async dredgeStatus(context, payload) {
      const { businessId } = payload
      try {
        const { data } = await dredgeStatus(businessId)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 保存 新增
    async fetchBusinessAddSave(context, payload) {
      // const { searchName, status, businessType, perPage, page } = payload
      try {
        const { data } = await getBusinessAddSave(payload)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 获取详情
    async fetchBusinessEditDetails(context, payload) {
      const { businessId } = payload
      try {
        const { data } = await getBusinessEditDetails(businessId)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 保存 编辑
    async fetchBusinessEditSave(context, payload) {
      // const { searchName, status, businessType, perPage, page } = payload
      try {
        const { data } = await getBusinessEditSave(payload)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 删除 商户
    async fetchBusinessDelete(context, payload) {
      const { businessId } = payload
      try {
        const { data } = await getBusinessDelete(businessId)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 获取商户列表
    async fetchBusinessList(context, payload) {
      const { searchName, status, businessType, perPage, page } = payload
      try {
        const { data } = await getBusinessList(searchName, status, businessType, perPage, page)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 提交新增商户信息
    async fetchBusinessSubmit(context, payload) {
      const { businessName, stallName } = payload
      try {
        const { data } = await submitBusiness(businessName, stallName)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 获取绑定电子秤列表
    async fetchSerialList(context, payload) {
      const { businessId } = payload
      try {
        const { data } = await getSerialList(businessId)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 设置解绑电子秤
    async fetchSetSerialUnbind(context, payload) {
      const { businessId, serialNumber } = payload
      try {
        return await setSerialUnbind(businessId, serialNumber)
      } catch (err) {
        console.log(err)
      }
    },
    // 退租
    async fetchDeleteStall(context, payload) {
      const { businessId } = payload
      try {
        return await deleteStall(businessId)
      } catch (err) {
        console.log(err)
      }
    },

    // 商户详情
    async fetchBusinessDetails(context, payload) {
      const { businessId } = payload
      try {
        return await getBusinessDetailsData(businessId)
      } catch (err) {
        console.log(err)
      }
    },
    // 合同列表
    async fetchContractList(context, payload) {
      const { businessId, status, perPage, page } = payload
      try {
        return await getContractList(businessId, status, perPage, page)
      } catch (err) {
        console.log(err)
      }
    },
    // 缴费列表
    async fetchPayTheFeesList(context, payload) {
      const { businessId, businessName, payStatus, payType, perPage, page } = payload
      try {
        return await getPayTheFeesList(businessId, businessName, payStatus, payType, perPage, page)
      } catch (err) {
        console.log(err)
      }
    },
    // 检测信息列表
    async fetchCheckReportList(context, payload) {
      const { businessId, businessName, perPage, page } = payload
      try {
        return await getCheckReportList(businessId, businessName, perPage, page)
      } catch (err) {
        console.log(err)
      }
    },
    // 购进信息详情
    async fetchPurchaseDetail(context, payload) {
      const { businessId } = payload
      try {
        return await getPurchaseDetail(businessId)
      } catch (err) {
        console.log(err)
      }
    },
    // 商户交易信息列表
    async fetchTransactionList(context, payload) {
      const { marketId,
        businessId,
        code,
        startDate,
        endDate,
        payWay,
        perPage,
        page } = payload
      try {
        return await getTradingList(marketId, businessId, code, startDate, endDate, payWay, perPage, page)
      } catch (err) {
        console.log(err)
      }
    },

    // 获取健康证列表
    async fetchHealthList(context, payload) {
      const { businessId, perPage, page } = payload
      try {
        const { data } = await getHealthList(businessId, perPage, page)
        return data
      } catch (err) {
        console.log(err)
      }
    },

    // 新增健康证
    async fetchHealthAddSave(context, payload) {
      const { businessId, businessName, healthName, healthPhoto, healthDate } = payload
      try {
        const { data } = await getHealthAddSave(businessId, businessName, healthName, healthPhoto, healthDate)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 删除健康证
    async fetchHealthDelete(context, payload) {
      const { healthId } = payload
      try {
        const { data } = await getHealthDelete(healthId)
        return data
      } catch (err) {
        console.log(err)
      }
    },

    // 获取许可证列表
    async fetchLicenseList(context, payload) {
      const { businessId, perPage, page } = payload
      try {
        const { data } = await getLicenseList(businessId, perPage, page)
        return data
      } catch (err) {
        console.log(err)
      }
    },

    // 新增许可证
    async fetchLicenseAddSave(context, payload) {
      try {
        const { data } = await getLicenseAddSave(payload)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 删除许可证
    async fetchLicenseDelete(context, payload) {
      const { otherBusinessLicenseId } = payload
      try {
        const { data } = await getLicenseDelete(otherBusinessLicenseId)
        return data
      } catch (err) {
        console.log(err)
      }
    },

    // 上传营业执照 或 商户头像
    async fetchBusinessImg(context, payload) {
      const { businessId, type, imgUrl } = payload
      try {
        const { data } = await getBusinessImg(businessId, type, imgUrl)
        return data
      } catch (err) {
        console.log(err)
      }
    }
  }
}
